import {deleteSql, insertSql, objectToMap, selectSql, updateSql} from "../util/sqlUtils";
import {LocalChange} from "../sql/domin";
import {InputMapper} from "./InputMapper";
import {ChangeStatus, ChangeType, TargetType} from "../util/Constants";
import {getNVueFlexDirection, M} from "@dcloudio/uni-cli-shared";

export class LocalChangeMapper{

    public static async selectLocalChangeByTargetId(targetId:string,type:TargetType){
        return await selectSql('localChange',
            new Map<string, any>([
                ['targetId',targetId],
                ['targetType',type]
            ]))
    }

    public static async selectLocalChangeAllList(){
        return await selectSql('localChange')
    }

    public static selectLocalChangeList(userId:number,type:TargetType){
        return selectSql('localChange',
            new Map<string, any>([
                ['targetType',type],
                ['userId',userId]
            ]))
    }

    public static insertLocalChange(localChange:LocalChange){
        return insertSql('localChange',
            objectToMap(localChange)
        )
    }

    public static updateLocalChangeByUid(uid:string,changeType:ChangeType,time:string){
        return updateSql('localChange',
            new Map<string,any>([
                ['changeTime',time]
            ]),`where targetId = '${uid}' and changeType = '${changeType}'`
            )
    }

    public static updateLocalChangeStatusById(status:ChangeStatus,id:number){
        return updateSql('localChange',new Map([['changeStatus',status]]),'where id = ' + id)
    }

    public static deleteLocalChangeById(id:number){
        return deleteSql('localChange','where id = ' +id)
    }

    public static deleteLocalChangeByTargetId(targetId:string,type:TargetType){
        return deleteSql('localChange',new Map<string, any>([
            ['targetId',targetId],
            ['targetType',type]
        ]))
    }

}
